package com.xx.java8.chapter4;

import java.io.IOException;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.Arrays;
import java.util.stream.IntStream;
import java.util.stream.Stream;

public class MainApp2 {
    public static void main(String[] args) {
        IntStream.rangeClosed(1, 20).filter(x -> x % 2 == 0).forEach(System.out::println);

        Stream<String> stringStream = Stream.of("Java 8 ", "Lambdas ", "In ", "Action");
        stringStream.map(s -> s.toUpperCase()).forEach(System.out::println);

        Stream<String> emptyStream = Stream.empty();
        System.out.println(emptyStream);

        try (Stream<String> linesStream = Files.lines(Paths.get("src/data.txt"), Charset.defaultCharset())) {
            long count = linesStream
                    .flatMap(line -> Arrays.stream(line.split(" ")))
                    .distinct()
                    .count();
            System.out.println(count);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
